import com.ridgesoft.intellibrain.IntelliBrain;
import com.ridgesoft.intellibrain.IntelliBrainDigitalIO;

public class Odometry implements Runnable{
	
	//Ports, counter, digital IO
	private static int ODO_PORT = 11;
	private int _count;
	private IntelliBrainDigitalIO odom;
	private static final Odometry instance = new Odometry();
	private boolean curr = false;
	private boolean prev = false;
	
	
	public Odometry()
	{		
	}
	public void init()
	{
		odom = IntelliBrain.getDigitalIO(ODO_PORT);
		odom.setPullUp(true);
	}
	public int getCount(){
		return _count;
	}
	public void resetCount(){
		_count = 0;
	}
	public void UpdateSensors()
	{		
		curr = odom.isSet();
		if((!prev) && (curr)){
			_count++;
		} 
		prev = curr;
	}
	@Override
	public void run() 
	{
		init();
		while(true)
		{
			Thread.yield();
			UpdateSensors();
		}
	}
	  public static Odometry getInstance() {
	        return instance;
	    }

	
}
